import axios from 'axios'
import Vue from 'vue'
import { Toast } from 'vant';
Vue.use(Toast);
const instance = axios.create({
    baseURL: 'http://kumanxuan1.f3322.net:8001',
    timeout: 5000
})

//请求拦截器
instance.interceptors.request.use(config => {

    // console.log('config为：',config);
    let token = localStorage.getItem('token')
    if (token) {
        config.headers['X-Nideshop-Token'] = token
        
    }
    // 加载提示
    Toast.loading({
        message: '加载中...',
        forbidClick: true,
    });
    return config
}, err => {
    return Promise.reject(err)
})

//响应拦截
instance.interceptors.response.use(res => {
    // console.log(res); 
    Toast.clear();
    return res.data
    
}, err => {
    Toast.clear();
    return Promise.reject(err)
})





export default instance